package com.example.shop_2211

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseActivity
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2211.databinding.ActivityMainBinding
import com.example.shop_2211.fgViewModel.MineViewModel
import com.example.shop_2211.login.UpdatePwdActivity
@Route(path = "/app/MainActivity")
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    @Autowired
    @JvmField
    var index = 0
    override fun initView() {
        ARouter.getInstance().inject(this)
        //获取动态权限
        requestPermissions(arrayOf("android.permission.WRITE_EXTERNAL_STORAGE",
            "android.permission.READ_EXTERNAL_STORAGE"),100)


      /* viewModel.getUser()
        binding.updatePwd.setOnClickListener {
            val intent = Intent(this,UpdatePwdActivity::class.java)
            startActivity(intent)
        }*/
        val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
        val navController = navHostFragment.navController
        binding.bottom.setupWithNavController(navController)

        when(index){
            0->{
                binding.bottom.selectedItemId = R.id.homeFragment
            }
            1->{
                binding.bottom.selectedItemId = R.id.categoryFragment
            }
            2->{
                binding.bottom.selectedItemId = R.id.cartFragment
            }
            3->{
                binding.bottom.selectedItemId = R.id.mineFragment
            }
        }
    }

    override fun initData() {
       /* viewModel.getUserSuccess.observe(this){
            if(it.code==200){
                binding.info = it.data
            }else{
                ToastUtils.showLong(it.message)
            }
        }
        viewModel.getUserFail.observe(this){
            ToastUtils.showLong(it)
        }*/
    }

   /* override fun getViewModel(): Class<MineViewModel>  = MineViewModel::class.java*/

    override fun getLayout(): Int  = R.layout.activity_main

}